<template>
  <header id="header">
    <div class="l-content">
      <el-button type="danger" icon="el-icon-menu" size="small" @click="collapseMenu"></el-button>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item :to="current.path" v-if="current">{{ current.label }} </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="r-content">
      <el-dropdown trigger="click">
        <span class="el-dropdown-link"><img :src="userImg" class="userImg" /></span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item>个人中心</el-dropdown-item>
          <!-- 这个组件没有提供click方法,所以需要加一个native修饰符,  意思就是使用原生的点击事件 -->
          <el-dropdown-item @click.native="exit">退出</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </header>
</template>

<script>
import { mapState } from 'vuex'
export default {
  computed: {
    ...mapState({
      // 这就是一个计算属性的简写方式
      current: (state) => state.tab.currentMenu,
    }),
  },
  data() {
    return {
      userImg: require('../assets/image/touxiang.jpg'),
    }
  },
  methods: {
    collapseMenu() {
      this.$store.commit('collapseMenu')
    },
    exit() {
      this.$store.commit('clearToken')
      this.$store.commit('clearMenu')
      // 刷新浏览器
      location.reload()
    },
  },
}
</script>

<style lang="scss" scoped>
header {
  display: flex;
  height: 100%;
  align-items: center;
  justify-content: space-between;
  .userImg {
    width: 44px;
    height: 44px;
    border-radius: 50%;
  }
  .l-content {
    display: flex;
    align-items: center;
    .el-breadcrumb {
      margin-left: 30px;
    }
  }
  ::v-deep .el-breadcrumb__inner {
    color: #a9a9a9;
    font-weight: 400;
  }
  ::v-deep .el-breadcrumb__item:last-child .el-breadcrumb__inner {
    font-weight: 600;
    color: #fa8072;
  }
}
</style>
